#include <nxos.h>

NX_PRIVATE NX_Error ThreadSnapshotTest()
{
    NX_Error err = NX_EOK;
    NX_SnapshotThread snapshotInfo;

    NX_Solt solt = NX_SnapshotCreate(NX_SNAPSHOT_THREAD, 0);
    if (solt == NX_SOLT_INVALID_VALUE)
    {
        NX_Printf("Create snapshot failed!");
        return err;
    }

    if ((err = NX_SnapshotFirst(solt, (void *)&snapshotInfo)) == NX_EOK)
    {
        do
        {
            NX_Printf("thread:%s tid:%d state:%d owner pid:%d base priority:%d cur priority:%d\r\n",
                      snapshotInfo.name, snapshotInfo.threadId, snapshotInfo.state,
                      snapshotInfo.ownerProcessId, snapshotInfo.fixedPriority, snapshotInfo.priority);
        } while((err = NX_SnapshotNext(solt, (void *)&snapshotInfo)) == NX_EOK);
    }

    NX_SoltClose(solt);
    return NX_EOK;
}

NX_PRIVATE NX_Error ProcessSnapshotTest()
{
    NX_Error err = NX_EOK;
    NX_SnapshotProcess snapshotInfo;

    NX_Solt solt = NX_SnapshotCreate(NX_SNAPSHOT_PROCESS, 0);
    if (solt == NX_SOLT_INVALID_VALUE)
    {
        NX_Printf("Create snapshot failed!");
        return err;
    }

    if ((err = NX_SnapshotFirst(solt, (void *)&snapshotInfo)) == NX_EOK)
    {
        do
        {
            NX_Printf("procss:%s pid:%d ppid:%d thread count:%d\r\n",
                      snapshotInfo.exePath, snapshotInfo.processId, snapshotInfo.parentProcessId, snapshotInfo.threadCount);
        } while((err = NX_SnapshotNext(solt, (void *)&snapshotInfo)) == NX_EOK);
    }

    NX_SoltClose(solt);
    return NX_EOK;
}

NX_Error TEST_Snapshot(char *cmdline)
{
    ThreadSnapshotTest();
    ProcessSnapshotTest();
    return NX_EOK;
}
